#ifndef INTERFACE_H_
#define INTERFACE_H_
/*********************************************************/
#include <Poco/Runnable.h>
#include <Poco/Thread.h>
#include <Poco/Mutex.h>
#include <queue>
#include <string>
#include <utility>
#include <sstream>
/*********************************************************/
class Interface : public Poco::Runnable
{
private:
	// Variables
	Poco::Thread					uiThread;	// The thread handling input
	bool 						stopSignal;	// A stop signal to signal a stop to the class
	static Poco::Mutex*				mutex;		// Mutual exclusion for thread safety
	std::string					input;		// Stores the current input
	std::ostringstream				output;		// Stringstream storing the output of the interface
	std::string					ifThreadName;	// The input thread name
	std::string					inputEventStr;	// Input event string identification
	std::queue<std::string>				cmdQueue; 	// Command storage queue
	static Interface&				pInstance;	// Only available instance of the interface

	// Methods
	void processKey(const int ch);					// Processes key strokes and modifies the input string accordingly
	void run();							// Entry point for the interface thread
	void display();							// Displays the current interface text to the screen

	// Prohibit the user of manual construction/copy construction
	Interface();							// Constructor
	Interface(const Interface&);					// Copy Constructor
	const Interface& operator=(const Interface&);			// Assignment operator

public:
	// Methods
	bool pop(std::string&);						// Returns and removes the next command from the queue
	bool pop();							// Removes the next command from the queue
	bool peek(std::string&);					// Returns the next command in the queue ( doesn't remove it )
	void start(const std::string&);					// Start the interface thread, the interface becomes available to accept input
	void stop();							// Stops the interface thread and the interface goes offline no long processing input
	void flush();							// Flushes output to the screen ( updates the screen )
	std::string dump();						// Return the interface text as a string
	void dump(const std::string&);					// Dump the interface text to a file
	std::ostream& operator<<(const std::string&);			// Send output to the interface

	// Construction & Destruction
	static Interface& Instance();				// Instance fetch
	virtual ~Interface();					// Destructor
};
/*********************************************************/
#endif // INTERFACE_H_